package com.example.mitsuki_momo_livestreamingschedule;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @author ：lxb
 * @ProjectName: mitsuki_momo_liveStreamingSchedule
 * @Package: com.example.mitsuki_momo_livestreamingschedule
 * @ClassName: TermiusTestUtil
 * @date ：Created in  2023/3/8 13:44
 * @description：
 * @version: 1.0
 */
public class TermiusTestUtil {

    public static void main(String[] args) throws IOException {
        String name = "C:\\Users\\lxb42\\AppData\\Local\\Programs\\Termius\\termius.ini";
        String filename = "C:\\Users\\lxb42\\AppData\\Local\\Programs\\Termius\\resources\\app\\js\\entry.js";
//                filename = "C://Users//Administrator//AppData///Local//Programs//Termius//resources//app//js//main.js";
        // 使用ArrayList来存储每行读取到的字符串
        ArrayList<String> arrayList = new ArrayList<>();
        ArrayList<String> unTranslate = new ArrayList<>();
        String strs = "";
        try {
            FileReader fr = new FileReader(name);
            BufferedReader bf = new BufferedReader(fr);
            String str;
            // 按行读取字符串
            while ((str = bf.readLine()) != null) {
                arrayList.add(str);
            }
            bf.close();
            fr.close();
            fr = new FileReader(filename);
            bf = new BufferedReader(fr);
            while ((str = bf.readLine()) != null) {
                strs += str + "\r\n";
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 对ArrayList中存储的字符串进行处理
        int length = arrayList.size();

        for (int i = 0; i < length; i++) {
            String s = arrayList.get(i);
            String[] tab = s.split("\\|");
            if (tab.length!=2 && s.trim().length() > 4){
                System.out.println(s + "\r\n");
            }
            if (strs.contains(tab[0]) && tab.length==2 && !s.startsWith("#")){
                strs = strs.replace(tab[0],tab[1]);
                System.out.println(i + "   " +s);
            }else {
                unTranslate.add(s);
            }

        }
        FileWriter fileWriter = new FileWriter(filename);
        fileWriter.write(strs);
        fileWriter.flush();
        fileWriter.close();

        System.out.println(unTranslate);
    }

}
